//Design By Do Trung --- Email : trungqn19852003@yahoo.com
//Ngày Design :5/4/2011 5:00:13 PM
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Linq;
using System.Collections.Generic;
 
	/// <summary>
	/// </summary>
	public class TinTuc_DA
	{
		public TinTuc_DA() {}
#region 'Variables And Properties'
		 private int int_IdTinTuc ;
		 public int IdTinTuc
			{
			 get 	
				{
					 return this.int_IdTinTuc;
				}
			 set 	
				{
					int_IdTinTuc=value;
				}
			}
		 private int int_IdMenu ;
		 public int IdMenu
			{
			 get 	
				{
					 return this.int_IdMenu;
				}
			 set 	
				{
					int_IdMenu=value;
				}
			}
		 private string string_TenDangNhap ;
		 public string TenDangNhap
			{
			 get 	
				{
					 return this.string_TenDangNhap;
				}
			 set 	
				{
					string_TenDangNhap=value;
				}
			}
		 private string string_TieuDe ;
		 public string TieuDe
			{
			 get 	
				{
					 return this.string_TieuDe;
				}
			 set 	
				{
					string_TieuDe=value;
				}
			}
		 private string string_TomTat ;
		 public string TomTat
			{
			 get 	
				{
					 return this.string_TomTat;
				}
			 set 	
				{
					string_TomTat=value;
				}
			}
		 private string string_NoiDung ;
		 public string NoiDung
			{
			 get 	
				{
					 return this.string_NoiDung;
				}
			 set 	
				{
					string_NoiDung=value;
				}
			}
		 private DateTime DateTime_NgayTao ;
		 public DateTime NgayTao
			{
			 get 	
				{
					 return this.DateTime_NgayTao;
				}
			 set 	
				{
					DateTime_NgayTao=value;
				}
			}
		 private DateTime DateTime_NgayDang ;
		 public DateTime NgayDang
			{
			 get 	
				{
					 return this.DateTime_NgayDang;
				}
			 set 	
				{
					DateTime_NgayDang=value;
				}
			}
		 private string string_HinhAnh ;
		 public string HinhAnh
			{
			 get 	
				{
					 return this.string_HinhAnh;
				}
			 set 	
				{
					string_HinhAnh=value;
				}
			}
		 private string string_TuKhoa ;
		 public string TuKhoa
			{
			 get 	
				{
					 return this.string_TuKhoa;
				}
			 set 	
				{
					string_TuKhoa=value;
				}
			}
		 private string string_Tag ;
		 public string Tag
			{
			 get 	
				{
					 return this.string_Tag;
				}
			 set 	
				{
					string_Tag=value;
				}
			}
		 private string string_NguonTin ;
		 public string NguonTin
			{
			 get 	
				{
					 return this.string_NguonTin;
				}
			 set 	
				{
					string_NguonTin=value;
				}
			}
		 private bool bool_TinNoiBat ;
		 public bool TinNoiBat
			{
			 get 	
				{
					 return this.bool_TinNoiBat;
				}
			 set 	
				{
					bool_TinNoiBat=value;
				}
			}
		 private bool bool_ChoPhepBinhLuan ;
		 public bool ChoPhepBinhLuan
			{
			 get 	
				{
					 return this.bool_ChoPhepBinhLuan;
				}
			 set 	
				{
					bool_ChoPhepBinhLuan=value;
				}
			}
		 private int int_LuotXem ;
		 public int LuotXem
			{
			 get 	
				{
					 return this.int_LuotXem;
				}
			 set 	
				{
					int_LuotXem=value;
				}
			}
		 private bool bool_TrangThai ;
		 public bool TrangThai
			{
			 get 	
				{
					 return this.bool_TrangThai;
				}
			 set 	
				{
					bool_TrangThai=value;
				}
			}
		 private bool bool_Tinnong ;
		 public bool Tinnong
			{
			 get 	
				{
					 return this.bool_Tinnong;
				}
			 set 	
				{
					bool_Tinnong=value;
				}
			}
#endregion

		/// <summary>
		/// Inserts a record into the TinTuc table.
		/// <summary>
		/// <param name="IdTinTuc"></param>
		/// <param name="IdMenu"></param>
		/// <param name="TenDangNhap"></param>
		/// <param name="TieuDe"></param>
		/// <param name="TomTat"></param>
		/// <param name="NoiDung"></param>
		/// <param name="NgayTao"></param>
		/// <param name="NgayDang"></param>
		/// <param name="HinhAnh"></param>
		/// <param name="TuKhoa"></param>
		/// <param name="Tag"></param>
		/// <param name="NguonTin"></param>
		/// <param name="TinNoiBat"></param>
		/// <param name="ChoPhepBinhLuan"></param>
		/// <param name="LuotXem"></param>
		/// <param name="TrangThai"></param>
		/// <param name="Tinnong"></param>
		/// <returns></returns>
		public bool Insert(SqlConnection SqlCnn)
		{
			bool boolInsert = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TinTuc_Insert";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdTinTuc", SqlDbType.Int).Value=IdTinTuc;
			SqlCmd.Parameters.Add("@IdMenu", SqlDbType.Int).Value=IdMenu;
			SqlCmd.Parameters.Add("@TenDangNhap", SqlDbType.NVarChar,50).Value=TenDangNhap;
			SqlCmd.Parameters.Add("@TieuDe", SqlDbType.NVarChar,4000).Value=TieuDe;
			SqlCmd.Parameters.Add("@TomTat", SqlDbType.NText,1073741823).Value=TomTat;
			SqlCmd.Parameters.Add("@NoiDung", SqlDbType.NText,1073741823).Value=NoiDung;
			SqlCmd.Parameters.Add("@NgayTao", SqlDbType.DateTime).Value=NgayTao;
			SqlCmd.Parameters.Add("@NgayDang", SqlDbType.DateTime).Value=NgayDang;
			SqlCmd.Parameters.Add("@HinhAnh", SqlDbType.NVarChar,250).Value=HinhAnh;
			SqlCmd.Parameters.Add("@TuKhoa", SqlDbType.NVarChar,50).Value=TuKhoa;
			SqlCmd.Parameters.Add("@Tag", SqlDbType.NVarChar,50).Value=Tag;
			SqlCmd.Parameters.Add("@NguonTin", SqlDbType.NVarChar,50).Value=NguonTin;
            SqlCmd.Parameters.Add("@TinNoiBat", SqlDbType.Bit).Value = TinNoiBat;
            SqlCmd.Parameters.Add("@ChoPhepBinhLuan", SqlDbType.Bit).Value = ChoPhepBinhLuan;
			SqlCmd.Parameters.Add("@LuotXem", SqlDbType.Int).Value=LuotXem;
            SqlCmd.Parameters.Add("@TrangThai", SqlDbType.Bit).Value = TrangThai;
            SqlCmd.Parameters.Add("@Tinnong", SqlDbType.Bit).Value = Tinnong;

			SqlAdp.InsertCommand = SqlCmd;
			SqlAdp.InsertCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolInsert = true;
			}
			catch
			{
			boolInsert = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolInsert;
		}

		/// <summary>
		/// Selects a single record from the TinTuc table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable Select(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TinTuc_Select";
			SqlCmd.CommandType=CommandType.StoredProcedure;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
		}

		/// <summary>
		/// Selects a single record from the TinTuc table.
		/// <summary>
		/// <returns>DataTable</returns>
		public DataTable SelectPrimaryKey(SqlConnection SqlCnn)
		{
			DataTable dt = new DataTable();
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TinTuc_SelectPrimaryKey";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdTinTuc", SqlDbType.Int).Value=IdTinTuc;

			SqlAdp.SelectCommand = SqlCmd;
			SqlAdp.SelectCommand.ExecuteNonQuery();
			SqlAdp.Fill(dt);
			SqlCmd.Transaction.Commit();
			}
			catch
			{
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return dt;
			}

		/// <summary>
		/// Updates a record in the TinTuc table.
		/// <summary>
		/// <param name="IdTinTuc"></param>
		/// <param name="IdMenu"></param>
		/// <param name="TenDangNhap"></param>
		/// <param name="TieuDe"></param>
		/// <param name="TomTat"></param>
		/// <param name="NoiDung"></param>
		/// <param name="NgayTao"></param>
		/// <param name="NgayDang"></param>
		/// <param name="HinhAnh"></param>
		/// <param name="TuKhoa"></param>
		/// <param name="Tag"></param>
		/// <param name="NguonTin"></param>
		/// <param name="TinNoiBat"></param>
		/// <param name="ChoPhepBinhLuan"></param>
		/// <param name="LuotXem"></param>
		/// <param name="TrangThai"></param>
		/// <param name="Tinnong"></param>
		public bool Update(SqlConnection SqlCnn)
		{
			bool boolUpdate = false ;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TinTuc_Update";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdTinTuc", SqlDbType.Int).Value=IdTinTuc;
			SqlCmd.Parameters.Add("@IdMenu", SqlDbType.Int).Value=IdMenu;
			SqlCmd.Parameters.Add("@TenDangNhap", SqlDbType.NVarChar,50).Value=TenDangNhap;
			SqlCmd.Parameters.Add("@TieuDe", SqlDbType.NVarChar,4000).Value=TieuDe;
			SqlCmd.Parameters.Add("@TomTat", SqlDbType.NText,1073741823).Value=TomTat;
			SqlCmd.Parameters.Add("@NoiDung", SqlDbType.NText,1073741823).Value=NoiDung;
			SqlCmd.Parameters.Add("@NgayTao", SqlDbType.DateTime).Value=NgayTao;
			SqlCmd.Parameters.Add("@NgayDang", SqlDbType.DateTime).Value=NgayDang;
			SqlCmd.Parameters.Add("@HinhAnh", SqlDbType.NVarChar,250).Value=HinhAnh;
			SqlCmd.Parameters.Add("@TuKhoa", SqlDbType.NVarChar,50).Value=TuKhoa;
			SqlCmd.Parameters.Add("@Tag", SqlDbType.NVarChar,50).Value=Tag;
			SqlCmd.Parameters.Add("@NguonTin", SqlDbType.NVarChar,50).Value=NguonTin;
            SqlCmd.Parameters.Add("@TinNoiBat", SqlDbType.Bit).Value = TinNoiBat;
			SqlCmd.Parameters.Add("@ChoPhepBinhLuan", SqlDbType.Bit).Value=ChoPhepBinhLuan;
			SqlCmd.Parameters.Add("@LuotXem", SqlDbType.Int).Value=LuotXem;
			SqlCmd.Parameters.Add("@TrangThai", SqlDbType.Bit).Value=TrangThai;
            SqlCmd.Parameters.Add("@Tinnong", SqlDbType.Bit).Value = Tinnong;

			SqlAdp.UpdateCommand = SqlCmd;
			SqlAdp.UpdateCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolUpdate = true ;
			}
			catch
			{
			boolUpdate = false ;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolUpdate;
		}

		/// <summary>
		/// Deletes a record from the TinTuc table by a composite primary key.
		/// <summary>
		public bool Delete(SqlConnection SqlCnn)
		{
			bool boolDelete = false;
			SqlDataAdapter SqlAdp = new SqlDataAdapter();
			SqlCommand SqlCmd = new SqlCommand();
			SqlTransaction SqlTrans = SqlCnn.BeginTransaction();
			try
			{
			SqlCmd.Transaction = SqlTrans;
			SqlCmd.Connection = SqlCnn;
			SqlCmd.CommandText="Proc_TinTuc_Delete";
			SqlCmd.CommandType=CommandType.StoredProcedure;
			SqlCmd.Parameters.Add("@IdTinTuc", SqlDbType.Int).Value=IdTinTuc;

			SqlAdp.DeleteCommand = SqlCmd;
			SqlAdp.DeleteCommand.ExecuteNonQuery();
			SqlCmd.Transaction.Commit();
			boolDelete = true;
			}
			catch
			{
                boolDelete = false;
			SqlCmd.Transaction.Rollback();
			}
			finally
			{
			SqlCmd.Parameters.Clear();
			SqlTrans = null;
			}
			if (SqlCmd != null)
			SqlCmd.Dispose();
			if (SqlAdp != null)
			SqlAdp.Dispose();
			return boolDelete;
			}
	}
 
